package com.excesys.exsecs.energy.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.energy.entity.BumSwitchRoom;
import com.excesys.exsecs.energy.service.DevSwitchRoomService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 供配电配电室
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/switchRoom")
@Tag(name = "供配电配电室")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class DevSwitchRoomController {

	private final DevSwitchRoomService devSwitchRoomService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param bumSwitchRoom
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('switchRoom_view')" )
	public R getPage(Page page, BumSwitchRoom bumSwitchRoom) {
		return R.ok(devSwitchRoomService.page(page, Wrappers.query(bumSwitchRoom).orderByAsc("create_time")));
	}

	/**
	 * 新增
	 * @param bumSwitchRoom 多个或单个对象
	 * @return
	 */
	@Operation(summary = "新增", description = "新增")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('switchRoom_add')" )
	public R save(@RequestBody BumSwitchRoom bumSwitchRoom) {
		return R.ok(devSwitchRoomService.save(bumSwitchRoom));
	}

	/**
	 * 修改
	 * @param bumSwitchRoom
	 * @return
	 */
	@Operation(summary = "修改", description = "修改")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('switchRoom_edit')" )
	public R edit(@RequestBody BumSwitchRoom bumSwitchRoom) {
		return R.ok(devSwitchRoomService.updateById(bumSwitchRoom));
	}

	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@Operation(summary = "删除", description = "删除")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('switchRoom_del')" )
	public R del(@PathVariable Long id) {
		return R.ok(devSwitchRoomService.removeById(id));
	}

	/**
	 * 通过主进线列表查询回路
	 */
	@Operation(summary = "通过主进线列表查询回路", description = "通过主进线列表查询回路")
	@GetMapping("/queryList")
	@PreAuthorize("@pms.hasPermission('switchRoom_view')" )
	public R queryList(){
		return R.ok(devSwitchRoomService.queryList());
	}
}